home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.09 Sep 91 / Bug Parser Code / Mini.windows.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-25  |  4.7 KB  |  235 lines  |  [TEXT/KAHL]

  1. /*********************************************************************
  2.  
  3.     mini.windows.c
  4.     
  5.     window functions for MiniEdit
  6.     
  7. *********************************************************************/
  8.  
  9. #include <QuickDraw.h>
  10. #include <MacTypes.h>
  11. #include <WindowMgr.h>
  12. #include <TextEdit.h>
  13. #include <ControlMgr.h>
  14. #include <EventMgr.h>
  15.  
  16. #include "MiniEdit.h"
  17.  
  18. extern WindowRecord     wRecord;
  19. extern WindowPtr     myWindow;
  20. extern ControlHandle vScroll;
  21. extern TEHandle      TEH;
  22. extern char             dirty;
  23. extern Str255          theFileName;
  24. extern int             linesInFolder;
  25.  
  26.  
  27. SetUpWindows()
  28. {
  29.     Rect    destRect, viewRect;
  30.     Rect    vScrollRect;
  31.     FontInfo    myInfo;
  32.     int        height;
  33.     
  34.     SetPort((myWindow = GetNewWindow( windowID, &wRecord, -1L )));
  35.     TextFont(4);
  36.     TextSize(9);
  37.     vScrollRect = (*myWindow).portRect;
  38.     vScrollRect.left = vScrollRect.right-15;
  39.     vScrollRect.right += 1;
  40.     vScrollRect.bottom -= 14;
  41.     vScrollRect.top -= 1;
  42.     vScroll = NewControl( myWindow, &vScrollRect, "\p", 1, 0, 0, 0,
  43.         scrollBarProc, 0L);
  44.  
  45.     viewRect = thePort->portRect;
  46.     viewRect.right -= SBarWidth;
  47.     viewRect.bottom -= SBarWidth;
  48.     InsetRect(&viewRect, 4, 4);
  49.     TEH = TENew( &viewRect, &viewRect );
  50.     SetView(thePort);
  51.     dirty = 0;
  52. }
  53.  
  54.  
  55. AdjustText ()
  56.  
  57. {
  58.     int        oldScroll, newScroll, delta;
  59.     
  60.     oldScroll = (**TEH).viewRect.top - (**TEH).destRect.top;
  61.     newScroll = GetCtlValue(vScroll) * (**TEH).lineHeight;
  62.     delta = oldScroll - newScroll;
  63.     if (delta != 0)
  64.       TEScroll(0, delta, TEH);
  65. }
  66.  
  67.  
  68. SetVScroll()
  69. {
  70.     register int    n;
  71.     
  72.     n = (**TEH).nLines-linesInFolder;
  73.  
  74.     if ((**TEH).teLength > 0 && (*((**TEH).hText))[(**TEH).teLength-1]=='\r')
  75.         n++;
  76.  
  77.     SetCtlMax(vScroll, n > 0 ? n : 0);
  78. }
  79.  
  80. ShowSelect()
  81.  
  82. {
  83.     register    int        topLine, bottomLine, theLine;
  84.     
  85.     SetVScroll();
  86.     AdjustText();
  87.     
  88.     topLine = GetCtlValue(vScroll);
  89.     bottomLine = topLine + linesInFolder;
  90.     
  91.     if ((**TEH).selStart < (**TEH).lineStarts[topLine] ||
  92.             (**TEH).selStart >= (**TEH).lineStarts[bottomLine]) {
  93.         for (theLine = 0; (**TEH).selStart >= (**TEH).lineStarts[theLine]; theLine++)
  94.             ;
  95.         SetCtlValue(vScroll, theLine - linesInFolder / 2);
  96.         AdjustText();
  97.     }
  98. }
  99.  
  100. SetView(w)
  101. WindowPtr w;
  102. {
  103.     (**TEH).viewRect = w->portRect;
  104.     (**TEH).viewRect.right -= SBarWidth;
  105.     (**TEH).viewRect.bottom -= SBarWidth;
  106.     InsetRect(&(**TEH).viewRect, 4, 4);
  107.     linesInFolder = ((**TEH).viewRect.bottom-(**TEH).viewRect.top)/(**TEH).lineHeight;
  108.     (**TEH).viewRect.bottom = (**TEH).viewRect.top + (**TEH).lineHeight*linesInFolder;
  109.     (**TEH).destRect.right = (**TEH).viewRect.right;
  110.     TECalText(TEH);
  111. }
  112.  
  113. UpdateWindow(theWindow)
  114. WindowPtr    theWindow;
  115. {
  116.     GrafPtr    savePort;
  117.     
  118.     GetPort( &savePort );
  119.     SetPort( theWindow );
  120.     BeginUpdate( theWindow );
  121.     EraseRect(&theWindow->portRect);
  122.     DrawControls( theWindow );
  123.     DrawGrowIcon( theWindow );
  124.     TEUpdate( &theWindow->portRect, TEH );
  125.     EndUpdate( theWindow );
  126.     SetPort( savePort );
  127. }
  128.  
  129.  
  130.  
  131.  
  132. pascal void ScrollProc(theControl, theCode)
  133. ControlHandle    theControl;
  134. int                theCode;
  135. {
  136.     int    pageSize;
  137.     int    scrollAmt;
  138.     
  139.     if (theCode == 0)
  140.         return ;
  141.     
  142.     pageSize = ((**TEH).viewRect.bottom-(**TEH).viewRect.top) / 
  143.             (**TEH).lineHeight - 1;
  144.             
  145.     switch (theCode) {
  146.         case inUpButton: 
  147.             scrollAmt = -1;
  148.             break;
  149.         case inDownButton: 
  150.             scrollAmt = 1;
  151.             break;
  152.         case inPageUp: 
  153.             scrollAmt = -pageSize;
  154.             break;
  155.         case inPageDown: 
  156.             scrollAmt = pageSize;
  157.             break;
  158.         }
  159.     SetCtlValue( theControl, GetCtlValue(theControl)+scrollAmt );
  160.     AdjustText();
  161.  
  162. }
  163.  
  164. DoContent(theWindow, theEvent)
  165. WindowPtr    theWindow;
  166. EventRecord    *theEvent;
  167. {
  168.     int                cntlCode;
  169.     ControlHandle     theControl;
  170.     int                pageSize;
  171.     GrafPtr            savePort;
  172.     
  173.     GetPort(&savePort);
  174.     SetPort(theWindow);
  175.     GlobalToLocal( &theEvent->where );
  176.     if ((cntlCode = FindControl(theEvent->where, theWindow, &theControl)) == 0) {
  177.         if (PtInRect( theEvent->where, &(**TEH).viewRect ))
  178.             TEClick( theEvent->where, (theEvent->modifiers & shiftKey )!=0, TEH);
  179.     }
  180.     else if (cntlCode == inThumb) {
  181.         TrackControl(theControl, theEvent->where, 0L);
  182.         AdjustText();
  183.     }
  184.     else
  185.         TrackControl(theControl, theEvent->where, &ScrollProc);
  186.  
  187.     SetPort(savePort);
  188. }
  189.  
  190. MyGrowWindow( w, p )
  191. WindowPtr w;
  192. Point p;
  193. {
  194.     GrafPtr    savePort;
  195.     long    theResult;
  196.     int        oScroll;
  197.     Rect     r, oView;
  198.     
  199.     GetPort( &savePort );
  200.     SetPort( w );
  201.  
  202.     SetRect(&r, 80, 80, screenBits.bounds.right, screenBits.bounds.bottom);
  203.     theResult = GrowWindow( w, p, &r );
  204.     if (theResult == 0)
  205.       return;
  206.     SizeWindow( w, LoWord(theResult), HiWord(theResult), 1);
  207.  
  208.     InvalRect(&w->portRect);
  209.     oView = (**TEH).viewRect;
  210.     oScroll = GetCtlValue(vScroll);
  211.     
  212.     SetView(w);
  213.     HidePen();
  214.     MoveControl(vScroll, w->portRect.right - SBarWidth, w->portRect.top-1);
  215.     SizeControl(vScroll, SBarWidth+1, w->portRect.bottom - w->portRect.top-(SBarWidth-2));
  216.     ShowPen();
  217.  
  218.  
  219.     SetVScroll();
  220.     AdjustText();
  221.     
  222.     SetPort( savePort );
  223. }
  224.  
  225.  
  226.  
  227. CloseMyWindow()
  228. {
  229.     HideWindow( myWindow );
  230.     TESetSelect( 0, (**TEH).teLength, TEH );
  231.     TEDelete( TEH );
  232.     SetVScroll();
  233.     SetUpFiles();
  234. }
  235.